VERSION 5.00
Begin VB.Form frmInvoiceIska 
   Caption         =   "חשבונית עסקה"
   ClientHeight    =   5760
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   8520
   LinkTopic       =   "Form1"
   ScaleHeight     =   5760
   ScaleWidth      =   8520
   StartUpPosition =   2  'CenterScreen
   Begin VB.TextBox txtVAT 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   3960
      TabIndex        =   32
      Text            =   "0.00"
      Top             =   4560
      Width           =   615
   End
   Begin VB.CommandButton cmdOpenInvoice 
      Caption         =   "Command1"
      Height          =   375
      Left            =   2760
      TabIndex        =   31
      Top             =   5280
      Visible         =   0   'False
      Width           =   2055
   End
   Begin VB.ComboBox lstTrxCodes 
      Height          =   315
      Left            =   120
      Style           =   2  'Dropdown List
      TabIndex        =   29
      Top             =   240
      Width           =   2655
   End
   Begin VB.CheckBox chkVAT 
      Caption         =   "לחייב מע""מ:"
      Height          =   255
      Left            =   5880
      TabIndex        =   16
      Top             =   4680
      Value           =   1  'Checked
      Width           =   2415
   End
   Begin VB.TextBox txtRebatePercent 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   4200
      TabIndex        =   14
      Text            =   "0"
      Top             =   3840
      Width           =   495
   End
   Begin VB.TextBox txtRebateNIS 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   6120
      TabIndex        =   13
      Text            =   "0.00"
      Top             =   3840
      Width           =   1095
   End
   Begin VB.CheckBox chkRound 
      Caption         =   "לעגל את הסכום הסופי:"
      Height          =   255
      Left            =   5880
      TabIndex        =   15
      Top             =   4320
      Width           =   2415
   End
   Begin VB.TextBox txtComments 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   120
      TabIndex        =   3
      Top             =   1680
      Width           =   5415
   End
   Begin VB.TextBox txtDetails 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   120
      TabIndex        =   2
      Top             =   1200
      Width           =   5415
   End
   Begin VB.TextBox txtItemDescription 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   2
      Left            =   5760
      TabIndex        =   10
      Top             =   3360
      Width           =   2535
   End
   Begin VB.TextBox txtUnitPrice 
      Height          =   285
      Index           =   2
      Left            =   4560
      TabIndex        =   11
      Top             =   3360
      Width           =   1095
   End
   Begin VB.TextBox txtItemQty 
      Height          =   285
      Index           =   2
      Left            =   3600
      TabIndex        =   12
      Top             =   3360
      Width           =   735
   End
   Begin VB.TextBox txtItemDescription 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   1
      Left            =   5760
      TabIndex        =   7
      Top             =   3000
      Width           =   2535
   End
   Begin VB.TextBox txtUnitPrice 
      Height          =   285
      Index           =   1
      Left            =   4560
      TabIndex        =   8
      Top             =   3000
      Width           =   1095
   End
   Begin VB.TextBox txtItemQty 
      Height          =   285
      Index           =   1
      Left            =   3600
      TabIndex        =   9
      Top             =   3000
      Width           =   735
   End
   Begin VB.TextBox txtItemQty 
      Height          =   285
      Index           =   0
      Left            =   3600
      TabIndex        =   6
      Top             =   2640
      Width           =   735
   End
   Begin VB.TextBox txtUnitPrice 
      Height          =   285
      Index           =   0
      Left            =   4560
      TabIndex        =   5
      Top             =   2640
      Width           =   1095
   End
   Begin VB.TextBox txtItemDescription 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   0
      Left            =   5760
      TabIndex        =   4
      Top             =   2640
      Width           =   2535
   End
   Begin VB.ComboBox lstCustomers 
      Height          =   315
      Left            =   4440
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   720
      Width           =   2535
   End
   Begin VB.CommandButton cmdOK 
      Caption         =   "OK"
      Height          =   375
      Left            =   1320
      TabIndex        =   17
      Top             =   5280
      Width           =   1095
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "יציאה"
      Height          =   375
      Left            =   120
      TabIndex        =   18
      Top             =   5280
      Width           =   975
   End
   Begin VB.Label Label16 
      Alignment       =   1  'Right Justify
      Caption         =   "אם אחוז המעמ הוא 0 אזי כספית תשלוף אותו מהנתונים שלה."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   177
         Weight          =   400
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   120
      TabIndex        =   34
      Top             =   4560
      Width           =   3375
   End
   Begin VB.Label Label15 
      Alignment       =   1  'Right Justify
      Caption         =   "אחוז המע""מ:"
      Height          =   255
      Left            =   4320
      TabIndex        =   33
      Top             =   4560
      Width           =   1335
   End
   Begin VB.Label Label12 
      Alignment       =   1  'Right Justify
      Caption         =   "סיווג תנועה:"
      Height          =   255
      Left            =   3000
      TabIndex        =   30
      Top             =   240
      Width           =   1095
   End
   Begin VB.Label Label11 
      Alignment       =   1  'Right Justify
      Caption         =   "אם תיאור הפריט הוא ריק המערכת לא תוסיף את הפריט לחשבונית"
      Height          =   615
      Left            =   480
      TabIndex        =   28
      Top             =   2640
      Width           =   2895
   End
   Begin VB.Label Label10 
      Alignment       =   1  'Right Justify
      Caption         =   "ההנחה בש""ח גוברת על ההנחה באחוזים."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   177
         Weight          =   400
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   240
      TabIndex        =   27
      Top             =   3840
      Width           =   3375
   End
   Begin VB.Label Label9 
      Alignment       =   1  'Right Justify
      Caption         =   "הנחה באחוזים:"
      Height          =   255
      Left            =   4680
      TabIndex        =   26
      Top             =   3840
      Width           =   1335
   End
   Begin VB.Label Label8 
      Alignment       =   1  'Right Justify
      Caption         =   "הנחה בש""ח:"
      Height          =   255
      Left            =   6960
      TabIndex        =   25
      Top             =   3840
      Width           =   1335
   End
   Begin VB.Label Label7 
      Alignment       =   1  'Right Justify
      Caption         =   "הערות לחשבונית (מוצגים ללקוח):"
      Height          =   255
      Left            =   5640
      TabIndex        =   24
      Top             =   1680
      Width           =   2655
   End
   Begin VB.Label Label6 
      Alignment       =   1  'Right Justify
      Caption         =   "פרטי החשבונית (לא מוצגים ללקוח):"
      Height          =   255
      Left            =   5160
      TabIndex        =   23
      Top             =   1200
      Width           =   3135
   End
   Begin VB.Label Label5 
      Alignment       =   1  'Right Justify
      Caption         =   "כמות"
      Height          =   255
      Left            =   3600
      TabIndex        =   22
      Top             =   2160
      Width           =   615
   End
   Begin VB.Label Label4 
      Alignment       =   1  'Right Justify
      Caption         =   "מחיר הפריט (לפני מע""מ)"
      Height          =   375
      Left            =   4200
      TabIndex        =   21
      Top             =   2160
      Width           =   1335
   End
   Begin VB.Label Label3 
      Alignment       =   1  'Right Justify
      Caption         =   "תיאור הפריט"
      Height          =   255
      Left            =   6960
      TabIndex        =   20
      Top             =   2160
      Width           =   1335
   End
   Begin VB.Label Label2 
      Alignment       =   1  'Right Justify
      Caption         =   "שם הלקוח:"
      Height          =   255
      Left            =   7200
      TabIndex        =   19
      Top             =   720
      Width           =   1095
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      Caption         =   "טופס יצירת חשבונית עסקה"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   5280
      TabIndex        =   0
      Top             =   120
      Width           =   3015
   End
End
Attribute VB_Name = "frmInvoiceIska"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Const MOD_NAME = "frmInvoiceIska."
Dim m_iInvoiceNum As Long

Private Sub cmdCancel_Click()
On Error Resume Next
    Unload Me
End Sub

Private Sub cmdOK_Click()
      Const FUNC_NAME = MOD_NAME & "cmdInvoice_Click"
10    On Error GoTo func_err
          
          Dim iCustomersID As Long
          Dim iTrxCodesID As Long
          Dim V
          Dim objCaspit As CaspitAPI.Caspit
          
20        If lstCustomers.ListIndex < 0 Then
30            MyErrMsgBox "חובה לבחור בלקוח"
40            Exit Sub
50        End If
60            If Len(txtItemDescription(0).Text) = 0 Then
70            MyErrMsgBox "חובה להכניס תיאור פריט"
80            Exit Sub
90        End If
100       If Len(txtUnitPrice(0).Text) = 0 Then
110           MyErrMsgBox "חובה להכניס מחיר פריט"
120           Exit Sub
130       End If
140       If Len(txtItemQty(0).Text) = 0 Then
150           MyErrMsgBox "חובה להכניס מחיר פריט"
160           Exit Sub
170       End If
          
180       V = Split(lstCustomers.List(lstCustomers.ListIndex), "-")
190       iCustomersID = V(UBound(V))
          
200       V = Split(lstTrxCodes.List(lstTrxCodes.ListIndex), "-")
210       iTrxCodesID = V(UBound(V))
          
          Dim varLineItems(2) As CaspitAPI.LineItem
          
220       Set objCaspit = New CaspitAPI.Caspit
          
          Dim I As Long
          
230       For I = 0 To 2
240     Set varLineItems(I) = New CaspitAPI.LineItem
250           varLineItems(I).ItemDescription = txtItemDescription(I)
260           If Len(txtUnitPrice(I)) > 0 Then varLineItems(I).UnitPrice = CCur(txtUnitPrice(I))
270           If Len(txtItemQty(I)) > 0 Then varLineItems(I).ItemQuantity = CDbl(txtItemQty(I))
280           varLineItems(I).CurrencyRate = 1#
290           varLineItems(I).ItemCurrency = "NIS"
300       Next
          
310       With objCaspit
320           .CaspitPath = g_strCaspitPath
330           .AccessPath = g_strAccessPath
340           .BusinessID = g_iBusinessID
350           .DebugMode = g_blnDebug
360       End With
          
370       m_iInvoiceNum = objCaspit.CreateInvoiceIska(iCustomersID, Date, _
        txtComments, txtRebatePercent, txtRebateNIS, chkRound.Value, txtVAT, chkVAT.Value, _
        txtDetails, _
        iTrxCodesID, _
        INVOICE_TYPE_STD, _
        varLineItems)
          
380       Set objCaspit = Nothing
          
390       cmdOpenInvoice.Caption = "הצג חשבונית " & m_iInvoiceNum
400       cmdOpenInvoice.Visible = True
          
410       MyMsgBox "חשבונית " & m_iInvoiceNum & " נוצרה בהצלחה."
        
420   Exit Sub

func_err:
430       MyErrMsgBox "Error " & Err.Number & " in " & Err.Source & ": " & Err.Description
440       Set objCaspit = Nothing
End Sub

Private Sub cmdOpenInvoice_Click()
Const FUNC_NAME = MOD_NAME & "cmdOpenInvoice_Click"
On Error GoTo func_err

    Dim objCaspit As CaspitAPI.Caspit
    
    Set objCaspit = New CaspitAPI.Caspit
    
    objCaspit.CaspitPath = g_strCaspitPath
    objCaspit.AccessPath = g_strAccessPath
    objCaspit.BusinessID = g_iBusinessID
    objCaspit.DebugMode = g_blnDebug
    
    Call objCaspit.DisplayInvoiceIska(m_iInvoiceNum)
    Set objCaspit = Nothing
Exit Sub

func_err:
    MyErrMsgBox "Error " & Err.Number & " in " & Err.Source & ": " & Err.Description
    Unload Me
End Sub

Private Sub Form_Load()
      Const FUNC_NAME = MOD_NAME & "Form_Load"
10    On Error GoTo func_err

20        PopulateCustomers
          
30        PopulateTrxCodes

40    Exit Sub

func_err:
50        MyErrMsgBox "Error " & Err.Number & " in " & Err.Source & ": " & Err.Description
60        Unload Me
End Sub

Private Sub PopulateCustomers()
      Const FUNC_NAME = MOD_NAME & "PopulateCustomers"
10    On Error GoTo func_err
          
          Dim V As Variant
          Dim I As Long
          
          Dim objCaspit As CaspitAPI.Caspit
          Dim objCustomer As CaspitAPI.Customer
          
20        Set objCaspit = New CaspitAPI.Caspit
          
30        With objCaspit
40            .CaspitPath = g_strCaspitPath
50            .AccessPath = g_strAccessPath
60            .BusinessID = g_iBusinessID
70            .DebugMode = g_blnDebug
80        End With
90        V = objCaspit.GetCustomers()
          
100       Set objCaspit = Nothing
          
110       If IsEmpty(V) Then Exit Sub
          
120       If UBound(V) < 0 Then
130           Err.Raise 1040, "", "יש ליצור לקוחות לפני שיוצרים חשבונית"
140       End If
          
          'Skip לקוח מזדמן
150       For I = 0 To UBound(V)
160           Set objCustomer = V(I)
              
170           Call lstCustomers.AddItem(objCustomer.BusinessName & " - " & objCustomer.CustomersID)
180       Next

190   Exit Sub

func_err:
200       Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
210       Set objCaspit = Nothing
End Sub

Private Sub PopulateTrxCodes()
Const FUNC_NAME = MOD_NAME & "PopulateTrxCodes"
10    On Error GoTo func_err
    
    Dim V As Variant
    Dim I As Long
    
    Dim objCaspit As CaspitAPI.Caspit
    Dim objTrxCode As CaspitAPI.TrxCode
    
20        Set objCaspit = New CaspitAPI.Caspit
    
30        With objCaspit
40            .CaspitPath = g_strCaspitPath
50            .AccessPath = g_strAccessPath
60            .BusinessID = g_iBusinessID
70            .DebugMode = g_blnDebug
80        End With
90        V = objCaspit.GetTrxCodes()
    
100       Set objCaspit = Nothing
    
110       If UBound(V) < 1 Then
120     Err.Raise 1040, "", "יש ליצור לקוחות לפני שיוצרים חשבונית"
130       End If
    
    ' Use only Trx Codes which are income related (PLCodesID = 1)
140       For I = 1 To UBound(V)
150     Set objTrxCode = V(I)
160     If (objTrxCode.PLCodesID = 1) Then
170         Call lstTrxCodes.AddItem(objTrxCode.TrxCodeDescription & " - " & objTrxCode.TrxCodesID)
180     End If
190       Next

200   Exit Sub

func_err:
210       Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
220       Set objCaspit = Nothing
End Sub
